<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="copyright" content="www.infoearth.com" />
		<title>群测群防数据采集系统</title>
		<link rel="stylesheet" href="../css/api.css">
		<link rel="stylesheet" href="../css/base.css">
		<link rel="stylesheet" type="text/css" href="../css/api.css"/>
		<link rel="stylesheet" href="../lib/jquery.mobile-1.4.5/jquery.mobile-1.4.5.min.css">
		<script src="../lib/jquery.mobile-1.4.5/jquery.min.js"></script>
		<script src="../lib/jquery.mobile-1.4.5/jquery.mobile-1.4.5.min.js"></script>
		<script type="text/javascript" src="../script/api.js"></script>
		<script src="../lib/config.js"></script>
		<script src="../lib/common.js"></script>
	</head>
	<body>
		<div id="wrap">
			<header id='header'>
				<nav id="nav">
					<a id="left" onclick="api.closeWin();"> <span>返回</span> </a>
					<div id="middle">
						<strong id="title">监测点列表</strong>
					</div>
					<a class="rightAdd" id="btnAddPnt"><span>添加</span></a>
				</nav>
			</header>
			<div id="main"></div>
		</div>
	</body>
	<script>
		var hazardInfo = null;
		var monitorRecord = [];
		apiready = function() {
			api.addEventListener({
				name : 'keyback'
			}, function(ret, err) {
				api.closeWin();
			});
			api.showProgress({
				style : 'default',
				animationType : 'fade',
				title : '正在加载监测点列表',
				text : '请稍等...',
				modal : false
			});
			hazardInfo = getCookie('hazardInfo');
			if (hazardInfo == null || hazardInfo == '') {
				return;
			}
			hazardInfo = JSON.parse(hazardInfo);
			$.ajax({
				url : ip_req + 'ZHFZ/ZHFZService.svc/GetListQCQFJCD01',
				type : 'GET',
				dataType : 'jsonp',
				data : {
					QCQFJCD01020 : hazardInfo.JBQK0100,
				}
			}).done(function(res) {
				api.hideProgress();
				showMonitorList(res.data);
			});
//			var qcqfdGuid = hazardInfo.QCQFD01010;
//			var filter = "QCQFJCD01020='" + qcqfdGuid + "'";
//			getRecordsByFilter("qcqf", "QCQFJCD01", filter, function(response) {
//				if (response != null && response.record != null && response.record.length > 0) {
//					showMonitorList(response.record);
//				}
//			}, showErro, false);
			api.hideProgress();
			$("#btnAddPnt").click(function() {
				api.openWin({
					name : 'andPoint',
					url : '../html/andPoint.html'
				});
			});
		}
		function getMonitorType(typeCode) {
			var typeName = '未知监测类别';
			switch(typeCode) {
				case 'HGXC':
					typeName = '宏观巡查';
					break;
				case 'DG':
					typeName = '地鼓';
					break;
				case'DL':
					typeName = '地缝缝宽';
					break;
				case 'QL':
					typeName = '墙裂缝宽';
					break;
				case 'JS':
					typeName = '井水';
					break;
				case 'QS':
					typeName = '泉水';
					break;
				default:
					break;
			}
			return typeName;
		}

		function showMonitorList(record) {
			monitorRecord = record;
			var dataList = [];
			var iconPath = 'widget://image/goto.png';
			for (var i = 0; i < record.length; i++) {
				var item = {
					uid : record[i].QCQFJCD01010,
					imgPath : '',
					title : record[i].QCQFJCD01070,
					subTitle : getMonitorType(record[i].QCQFJCD01030),
					icon : iconPath,
				};
				dataList.push(item);
			}
			var header = $api.byId('header');
			var headerPos = $api.offset(header);
			var lstView = api.require('UIListView');
			lstView.open({
				rect : {
					x : headerPos.l,
					y : headerPos.t + headerPos.h,
					w : api.frameWidth,
					h : api.frameHeight - headerPos.h
				},
				data : dataList,
				styles : {
					borderColor : '#EEEEEE',
					item : {
						bgColor : '#F5F5F5',
						activeBgColor : '#AFEEEE',
						height : 55.0,
						imgWidth : 32,
						imgHeight : 32,
						placeholderImg : '',
						titleSize : 16.0,
						titleColor : '#000',
						subTitleSize : 11.0,
						subTitleColor : '#000'
					}
				},
				fixedOn : ''
			}, function(ret) {
				listView_Click(ret);
			});
		}

		function listView_Click(ret) {
			if (ret.index < 0 || monitorRecord == null || monitorRecord.length < 1 || ret.eventType == 'show')
				return;
			var monitorPointInfo = monitorRecord[ret.index];
			setCookie('monitorPointInfo', JSON.stringify(monitorPointInfo));
			var monitorType = monitorPointInfo.QCQFJCD01030;
			//打开监测数据采集页面
			// showMsg("listView_Click():" + monitorType);
			switch(monitorType) {
				case 'HGXC':
					api.openWin({
						name : 'HGXC',
						url : '../html/HGXC.html'
					});
					break;
				case 'DG':
					api.openWin({
						name : 'DG',
						url : '../html/DG.html'
					});
					break;
				case'DL':
					api.openWin({
						name : 'DL',
						url : '../html/DL.html'
					});
					break;
				case 'QL':
					api.openWin({
						name : 'QL',
						url : '../html/QL.html'
					});
					break;
				case 'JS':
					api.openWin({
						name : 'JS',
						url : '../html/JS.html'
					});
					break;
				case 'QS':
					api.openWin({
						name : 'QS',
						url : '../html/QS.html'
					});
					break;
				default:
					break;
			}
		}
	</script>
</html>